<template>
	<!-- 认证资料填写页 -->
	<view class="content">
		<view class="form">
			<view class="authentication-top">
				<text>主办方名称</text><text class="mi">*</text><input type="text" placeholder="填写您的营业执照上的名称" maxlength=-1 v-model="authenticationSponsorName"/>
			</view>
			<view class="authentication-top">
				<text>主办方电话</text><text class="mi">*</text><input type="text" placeholder="填写您的公司电话" maxlength=11 v-model="authenticationSponsorPhone"/>
			</view>
			<view class="authentication-top">
				<text>法人名字</text><text class="mi">*</text><input type="text" placeholder="填写您的营业执照上法人名字" maxlength=-1 v-model="authenticationSponsorLegalName"/>
			</view>
			<view class="authentication-middle">
				<text>营业执照</text><text class="mi">*</text>
				<view class="middle-img">
					<text class="txt1">营业执照</text>
				    <image :src="authenticationSponsorImage||'/static/images/addImage.png'" @click="chooseImage1"></image>
				    <text class="txt1 text1">示例：</text>
				    <image class="examples" src="../../static/images/examples.png"></image>
				</view>
			</view>
			<view class="authentication-middle">
				<text>法人身份证</text><text class="mi">*</text>
				<view class="middle-img">
					<text class="txt2">身份证正面</text>
				    <image :src="idcardImageOne||'/static/images/addImage.png'" @click="chooseImage2"></image>
				    <text class="txt2 text2">身份证背面</text>
				    <image :src="idcardImageTwo||'/static/images/addImage.png'" class="back" @click="chooseImage3"></image>
				</view>
			</view>
		</view>
		<view class="bottom_pay_con">
			<!-- 模态弹框 -->
			<u-modal v-model="show" :title-style="{color: 'red'}" :show-title="false" :show-confirm-button="false" :mask-close-able="true">
				<view class="slot-content">
					<view class="popup_container">
						<view class="img_con"><image class="img" :src="url" mode="widthFix"></image></view>
						    <view class="text_con">
							    <view class="title">{{content.title}}</view>
							    <view class="content">{{content.text}}</view>
						    </view>
						<view class="bc_con"></view>
					</view>
				</view>
			</u-modal>
			<button class="pay_btn" type="default" @click="isAuthentication">确定认证</button>
			<!-- <button class="pay_btn" type="default" @click="goIndex">确定认证</button> -->
		</view>
	</view>
</template>

<script>
	export default {
		name: 'applyPopup',
		props: {
			url: {
				type: String,
				default: '/static/images/submit2.png'
			},
			content:{
				type:Object,
				default:()=>{
					return{
						title:"亲，您的认证资料提交成功了～",
						text:"请保持手机通畅，我们将和您联系"
					}
				}
			}
		},
		data() {
			return {
				show: false,
				authenticationSponsorName:"",
				authenticationSponsorPhone:"",
				authenticationSponsorLegalName:"",
				authenticationSponsorImage:"",
				idcardImageOne:"",
				idcardImageTwo:""
			}
		},
		created(){
			// console.log(this.url)
		},
		onNavigationBarButtonTap(){
			uni.navigateBack({
				
			})
		},
		methods: {
			goIndex(){
				uni.navigateTo({
					url:"../index/index"
				})
			},
			//验证公司名
			passSponsorName() {
				let reg = /^\w{1,20}$/;
				let passSponsorName = reg.test(this.authenticationSponsorName);
				return passSponsorName
			},
			//验证公司电话
			passSponsorTel() {
				let reg = /^\d{4,11}$/;
				let passSponsorTel = reg.test(this.authenticationSponsorPhone);
				return passSponsorTel
			},
			//验证法人
			passLegalName() {
				let reg = /^\w{2,8}$/;
				let passLegalName = reg.test(this.authenticationSponsorLegalName);
				return passLegalName
			},
			//选图
			chooseImage1(){
				let token=uni.getStorageSync('token');
				// console.log(token)
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths[0];
						this.authenticationSponsorImage=tempFilePaths;
						// console.log(tempFilePaths)
						uni.uploadFile({
							url:'https://products.rimiedu.com:8085/comic-time/putImage',
							filePath: tempFilePaths,
							name:'file',
							method:"POST",
							formData:{
								// 'file':chooseImageRes.tempFiles[0].name
							},
							header:{
								'Authorization':token
							},
							success:(uploadFileRes) => {
								// console.log(uploadFileRes)
							}
						})
					},
					count: 1,
					sizeType: ['original', 'compressed']
				})
			},
			//选图
			chooseImage2(){
				let token=uni.getStorageSync('token');
				// console.log(token)
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths[0];
						this.idcardImageOne=tempFilePaths;
						// console.log(tempFilePaths)
						uni.uploadFile({
							url:'https://products.rimiedu.com:8085/comic-time/putImage',
							filePath: tempFilePaths,
							name:'file',
							method:"POST",
							formData:{
								// 'file':chooseImageRes.tempFiles[0].name
							},
							header:{
								'Authorization':token
							},
							success:(uploadFileRes) => {
								// console.log(uploadFileRes)
							}
						})
					},
					count: 1,
					sizeType: ['original', 'compressed']
				})
			},
			//选图
			chooseImage3(){
				let token=uni.getStorageSync('token');
				// console.log(token)
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths[0];
						this.idcardImageTwo=tempFilePaths;
						// console.log(tempFilePaths)
						uni.uploadFile({
							url:'https://products.rimiedu.com:8085/comic-time/putImage',
							filePath: tempFilePaths,
							name:'file',
							method:"POST",
							formData:{
								// 'file':chooseImageRes.tempFiles[0].name
							},
							header:{
								'Authorization':token
							},
							success:(uploadFileRes) => {
								// console.log(uploadFileRes)
							}
						})
					},
					count: 1,
					sizeType: ['original', 'compressed']
				})
			},
			//上传数据
			isAuthentication(){
				if (this.passSponsorName() && this.passSponsorTel() && this.passLegalName() && this.authenticationSponsorImage && this.idcardImageOne && this.idcardImageTwo) {
				    this.show = true;
				    let token=uni.getStorageSync('token');
				    this.$request('/comic-time/addAuthentication',{
					    "authenticationSponsorName": this.authenticationSponsorName,
					    "authenticationSponsorPhone": this.authenticationSponsorPhone,
					    "authenticationSponsorLegalName": this.authenticationSponsorLegalName,
					    "authenticationSponsorImage": this.authenticationSponsorImage,
					    "idcardImageOne": this.idcardImageOne,
					    "idcardImageTwo": this.idcardImageTwo
					    },
					    'POST',
					    {"Authorization":token}
					    ).then(res => {
						    // console.log(res)
				    })
				} else {
					uni.showToast({
						title: "格式错误",
						position: "center",
						icon: "none",
						duration: 2000,
						mask: true
					});
				}
				//本地实验接口
				// uni.request({
			 //        url: 'http://192.168.7.43:8082/comic-time/addAuthentication', //仅为示例，并非真实接口地址。
			 //        data: {
			 //            "authenticationSponsorName": this.authenticationSponsorName,
			 //            "authenticationSponsorPhone": this.authenticationSponsorPhone,
			 //            "authenticationSponsorLegalName": this.authenticationSponsorLegalName,
			 //            "authenticationSponsorImage": this.authenticationSponsorImage,
			 //            "idcardImageOne": this.idcardImageOne,
			 //            "idcardImageTwo": this.idcardImageTwo
			 //        },
			 //        method:'POST',
			 //        header: {
			 //            "Authorization":token, //自定义请求头信息
			 //        },
			 //        success: (res) => {
			 //            console.log(res)
			 //        }
			 //    });
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../authentication/authentication.scss'
</style>
